﻿// Imports
using System;

namespace Nickel
{

    /// <summary>
    /// Summary description for Sort
    /// </summary>
    public class Sort
    {

        /// <summary>
        /// Sort method for author
        /// </summary>
        /// <param name="x">Author X</param>
        /// <param name="y">Author Y</param>
        /// <returns>-1 for x, 1 for y, and 0 for match</returns>
        public static int AuthorByName(Author x, Author y)
        {

            // DO IT!
            return x == null ? y == null ? 0 : -1 : y == null ? 1 : x.Name.CompareTo(y.Name);

        }

        /// <summary>
        /// Sort method for articles
        /// </summary>
        /// <param name="x">Article X</param>
        /// <param name="y">Article Y</param>
        /// <returns>1 for x, -1 for y, and 0 for match</returns>
        public static int ArticleByDate(Article x, Article y)
        {

            // Flip result for descending order
            return -(x == null ? y == null ? 0 : -1 : y == null ? 1 : DateTime.Parse(x.CreationDateTime).CompareTo(DateTime.Parse(y.CreationDateTime)));

        }

        /// <summary>
        /// Sort method for comments
        /// </summary>
        /// <param name="x">Comment X</param>
        /// <param name="y">Comment Y</param>
        /// <returns>1 for x, -1 for y, and 0 for match</returns>
        public static int CommentByDate(Comment x, Comment y)
        {

            // Order by date
            return x == null ? y == null ? 0 : -1 : y == null ? 1 : DateTime.Parse(x.CreationDateTime).CompareTo(DateTime.Parse(y.CreationDateTime));

        }

        /// <summary>
        /// Sort method for search results
        /// </summary>
        /// <param name="x">Search result X</param>
        /// <param name="y">Search result Y</param>
        /// <returns>-1 for x, 1 for y, and 0 for match</returns>
        public static int SearchResultByCount(SearchResult x, SearchResult y)
        {

            // DO IT!
            return -(x == null ? y == null ? 0 : -1 : y == null ? 1 : x.Count.CompareTo(y.Count));

        }

    }

}
